/*
*	Developed by Leonardo Chatain and Pedro Dusso, at Universidade Federal do Rio Grande do Sul, Brasil, 2009/1
*	Source available at glpacman.codeplex.com
*/

#include "Phantom.h"

int Phantom::globalColor = 0;

Phantom::Phantom(void)
{
	globalColor++;
	if (globalColor == 9)
		globalColor = 1;

	color = globalColor;
	position.setXY(0, 0);
	setDiscreteDirection(Character::up);
	turning = false;
	linearSpeed = 1;
	angularSpeed = 1;
	incomingDirection = discreteDirection;
	heigthPosition = CELL_SIZE/2;
	zombie = false;
	imuneToPac = false;
}

Phantom::Phantom(float x, float y) {
	Phantom();
	position.setXY(x, y);
}

Phantom::Phantom(Point2D pos) {
	Phantom(pos.getX(), pos.getY());
}

Phantom::Phantom(Point2D newPos, Vector2D dir) {
	Phantom();
	position.setXY(newPos.getX(), newPos.getY());
	direction.setX(dir.getX());
	direction.setY(dir.getY());
	direction.normalize();
}
Phantom::~Phantom(void)
{
}

void Phantom::draw(bool pacSuper) {
	glPushMatrix();
	
	glColor3f(VERY_LIGHT_BLUE);
	
	if(!pacSuper || imuneToPac) {
		switch(color) {
			case 1:
				glColor3f(PINK);
				break;
			case 2:
				glColor3f(CYAN);
				break;
			case 3:
				glColor3f(RED);
				break;
			case 4:
				glColor3f(ORANGE);
				break;
			case 5:
				glColor3f(DEEP_BLUE);
				break;
			case 6:
				glColor3f(BROWN);
				break;
			case 7:
				glColor3f(GREEN);
				break;
			case 8:
				glColor3f(VANILLA);
				break;
		}
	}
	if (zombie) {
		glColor3f(GRAY);
	}
	
	glTranslatef(position.getX(), heigthPosition, position.getY());

	float angle = direction.getAngleTo(Vector2D(1, 0));
	glRotatef(angle, 0, 1, 0);
	glRotatef(90, 1, 0, 0);
	GLUquadric *q = gluNewQuadric();
	gluCylinder(q, CHAR_RADIUS, CHAR_RADIUS, CHAR_RADIUS, CHARACTER_SLICES, CHARACTER_STACKS);
	glutSolidSphere(CHAR_RADIUS, CHARACTER_SLICES, CHARACTER_STACKS);
	glPopMatrix();
}
